/*-//GEN-BEGIN:copyright
 * ForBILE - Framework for Building Interactive Learning Environments
 * Computing Institute - Federal University of Alagoas - Brazil
 * Group of Otimization of the Web
 *
 * Copyright (C) 2007 Ig Bittencourt (ig.ibert@gmail.com)
 *		      Camila Nunes (camilapbnunes@hotmail.com)
 *	              Marcos Tadeu (zero.ufal@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *///GEN-END:copyright
package br.ufal.ic.forbile.agents.mediator.behaviours;

import java.util.logging.Logger;
import br.ufal.ic.forbile.infra.emathema.ontology.InstrutionalPlan;
import br.ufal.ic.forbile.log.MediatorAgentLog;
import br.ufal.ic.forbile.log.PersistenceOWLLog;
import br.ufal.ic.utils.Constants;
import br.ufal.ic.utils.RegionServer;
import br.ufal.ic.utils.SharedMem;
import jade.lang.acl.ACLMessage;
import java.io.IOException;
import java.rmi.Naming;

/**
 * Recommend1.java
 *
 * <p>A full description of this class.
 *
 * @see jade.core.behaviours.OneShotBehaviour.
 *
 * @author <a href="mailto:ig.ibert@gmail.com">ig</a>.
 * @since 0.1
 * @version 0.1
 *
 */
public class ATARecommend extends Recommend {
    
    // Constants -----------------------------------------------------
    
    // Attributes ----------------------------------------------------
    
    private String instrutionalPlan;
    
    // Static --------------------------------------------------------
    
    private static Logger logger;
    
    static {
        logger = Logger.getLogger(ATARecommend.class.getName());
    }
    
    // Constructors --------------------------------------------------
    
    /**
     * Creates a new instance of ATARecommend.
     *
     * @param instrutionalPlan The instrutional plan will be teached.
     */
    public ATARecommend(final String instrutionalPlan) {
        this.instrutionalPlan = instrutionalPlan;
    }
    
    // Public --------------------------------------------------------
    
    // OneShotBehaviour implementation -------------------------------
    
    public void recommend() {
        ACLMessage message = new ACLMessage(ACLMessage.INFORM);
        logger.info("-------- Mediator evaluates the recommendation process!-------- ");
        
        logger.info("-------- Request Instrutional Plan --------");
        
        PersistenceOWLLog persistenceLog = new PersistenceOWLLog();
        persistenceLog.setClass_("instrutionalPlan");
        persistenceLog.setIndividual(this.instrutionalPlan);
        persistenceLog.setRetrieveKey("Individual");
        
        MediatorAgentLog mal = new MediatorAgentLog();
        try {
            SharedMem mem = (SharedMem) Naming.lookup(RegionServer.HOST_URL);
            mal = (MediatorAgentLog) mem.getRegion(Constants.MediatorAgent).retrieveIfExist(mal);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        try {
            message.setContentObject(persistenceLog);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        message.addReceiver(mal.getAid());
        try {
            SharedMem mem = (SharedMem) Naming.lookup(RegionServer.HOST_URL);
            mem.getRegion(Constants.MediatorAgent).write(mal);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        this.myAgent.send(message);
        logger.info("-------- Instrutional Plan Message sent --------");
        try {
            
            SharedMem mem = (SharedMem) Naming.lookup(RegionServer.HOST_URL);
            persistenceLog = (PersistenceOWLLog) mem.getRegion(Constants.OWLPersistence).retrieveIfExist(persistenceLog);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        logger.info("-------- Instrutional Plan Retrieved --------");
        
        InstrutionalPlan ip = (InstrutionalPlan) persistenceLog.getIndividualOWL();
    }
    
    // Y overrides ---------------------------------------------------
    
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------
    
    // Private -------------------------------------------------------
    
    // Inner classes -------------------------------------------------
    
}
